package com.xyy.saas.payment.service.reconciliation;

import com.xyy.saas.payment.enums.ReconciliationType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author wangzeqi
 */
@Component
@ConditionalOnBean(ReconciliationStrategy.class)
public class ReconciliationStrategyFactory {

    private final Map<ReconciliationType, ReconciliationStrategy> strategies;

    @Autowired
    public ReconciliationStrategyFactory(List<ReconciliationStrategy> strategyList) {
        strategies = strategyList.stream()
                .collect(Collectors.toMap(
                        ReconciliationStrategy::getType,
                        Function.identity()
                ));
    }

    public ReconciliationStrategy getStrategy(ReconciliationType type) {
        return strategies.get(type);
    }

}
